package ServletController;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public LoginServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		
		String user = request.getParameter("user");
		String password = request.getParameter("password");
		
		HttpSession session = request.getSession();
		session.setAttribute("user", user);
		session.setAttribute("password", password);
		
//page 이동 forward 방식으로 하면 로그인후 메인페이지에서 새로고침할때 문제생김		
//		RequestDispatcher rd= request.getRequestDispatcher("main.html");
//		rd.forward(request, response);

		response.sendRedirect("test.html");
	}
}
